home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 24.6 KB | 944 lines | [TEXT/MPS ] |
- /*
- File: DrawEditorUtils.cpp
-
- Contains: DrawEditor utility functions & classes
-
- Written by: Adapted from SamplePartUtils.cpp and enhanced by Dave Stafford.
-
- Copyright: © 1994,95 by Apple Computer, Inc., all rights reserved.
- */
-
- // --- DrawEditor Includes ---
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- #ifndef _DRAWEDITORCONSTANTS_
- #include "DrawEditorConstants.h"
- #endif
-
- #ifndef _DRAWEDITORDEF_
- #include "DrawEditorDef.h"
- #endif
-
- #ifndef _SHAPES_
- #include "Shapes.h"
- #endif
-
- #ifndef _PROMISE_
- #include "Promise.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
-
- #ifndef _FOCUSLIB_
- #include "FocusLib.h"
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _TEMPITER_
- #include "TempIter.h"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _STORUTIL_
- #include "StorUtil.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- // --- Macintosh Includes ---
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef _STDLIB
- #include <StdLib.h>
- #endif
-
- #pragma segment DrawEditorUtilities
-
-
- //====================================================================
- // Utility Functions
- //====================================================================
-
- //------------------------------------------------------------------------------
- // DrawEditor Specific Utilities
- //------------------------------------------------------------------------------
-
- //--------------------------------------------------------------------
- // HiliteFacet
- //--------------------------------------------------------------------
- void HiliteFacet( Environment* ev, ODDragAndDrop* dad,
- ODFacet* facet, ODBoolean show)
- {
- CFocus forDrawing(ev, facet);
-
- ODFrame* displayFrame = facet->GetFrame(ev);
- ODShape* frameShape = displayFrame->AcquireFrameShape(ev, kODNULL);
- RgnHandle bRgn = frameShape->GetQDRegion(ev);
-
- // Release acquired geometry
- ODReleaseObject(ev, frameShape);
-
- if (show)
- ShowDragHilite(dad->GetDragReference(ev), bRgn, true);
- else
- HideDragHilite(dad->GetDragReference(ev));
- }
-
- //--------------------------------------------------------------------
- // MapRect
- //--------------------------------------------------------------------
- void MapRect( Rect& baseRect, Rect& resizeRect, Rect* result )
- {
-
- ODSShort ratio = (result->right - result->left) / (baseRect.right - baseRect.left);
-
- // Ration can't be 0
- if (ratio==0)
- ratio = 1;
-
- result->left += (resizeRect.left - baseRect.left) * ratio;
- result->right += (resizeRect.right - baseRect.right) * ratio;
-
- ratio = (result->bottom - result->top) / (baseRect.bottom - baseRect.top);
-
- // Ration can't be 0
- if (ratio==0)
- ratio = 1;
-
- result->top += (resizeRect.top - baseRect.top) * ratio;
- result->bottom += (resizeRect.bottom - baseRect.bottom) * ratio;
- }
-
- //--------------------------------------------------------------------
- // SortRect
- //--------------------------------------------------------------------
- void SortRect( Rect* rect )
- {
- if (rect->left > rect->right)
- {
- ODSShort temp = rect->left;
- rect->left = rect->right;
- rect->right = temp;
- }
- if (rect->top > rect->bottom)
- {
- ODSShort temp = rect->top;
- rect->top = rect->bottom;
- rect->bottom = temp;
- }
- }
-
- //--------------------------------------------------------------------
- // ValidRect
- //--------------------------------------------------------------------
- ODBoolean IsValidRect( Rect& rect )
- {
- return (rect.right>=rect.left && rect.bottom>=rect.top);
- }
-
- //--------------------------------------------------------------------
- // StrToShort
- //--------------------------------------------------------------------
- ODSShort StrToShort( StringPtr pstr )
- {
- // Throw if we get a bad parameter
- THROW_IF_NULL(pstr);
-
- // Allocate temp str
- // Throw if we don't get an allocation
- char* cstr = (char*)::ODNewPtr((ODUByte)pstr[0]);
- THROW_IF_NULL(cstr);
-
- // convert to cstr
- ODSByte size = pstr[0];
- memcpy(cstr, pstr+1, size);
- cstr[size+1] = 0L;
-
- // convert to integer
- return atoi(cstr);
- }
-
- //--------------------------------------------------------------------
- // NumToString
- //--------------------------------------------------------------------
- void NumToString( ODSShort number, char* result )
- {
- ODULong i = 0;
- ODULong num = number;
-
- do {
- result[i] = (ODSByte) (num % 10 + '0');
- if (result[i] > '9') DebugStr("\pError in NumToString");
- i++;
- } while ((num /= 10) > 0);
- result[i] = '\0';
-
- ODSByte c;
- ODULong j;
-
- for (i = 0, j = strlen(result)-1; i < j;i++, j--) {
- c = result[i];
- result[i] = result[j];
- result[j] = c;
- }
- c2pstr(result);
- }
-
- //--------------------------------------------------------------------
- // RectContainsRect
- //--------------------------------------------------------------------
- ODBoolean RectContainsRect(Rect& rect, Rect& inside)
- {
- Rect tRect = rect;
- Rect containsRect = inside;
-
- // Ensure similar co-ods
- OffsetRect(&tRect, -tRect.left, -tRect.top);
- OffsetRect(&containsRect, -containsRect.left, -containsRect.top);
-
- return (tRect.bottom <= containsRect.bottom && tRect.right < containsRect.right);
- }
-
- //--------------------------------------------------------------------
- // InspectShape
- //--------------------------------------------------------------------
- void ChangeFacetHighlight(Environment* ev,
- ODFacet* changeFacet,
- ODHighlight newHighlight)
- {
- // Notify the facet of the change
- changeFacet->ChangeHighlight(ev, newHighlight);
-
- // Invalidate the frame to redraw the changed facet
- ODFrame* tFrame = changeFacet->GetFrame(ev);
- tFrame->Invalidate(ev, kODNULL, kODNULL);
- }
- //--------------------------------------------------------------------
- // InspectShape
- //--------------------------------------------------------------------
- void InspectShape( Environment* ev, ODShape* shape )
- {
- RgnHandle shapeRgn = (shape->GetQDRegion(ev));
- Rect shapeRect = (**shapeRgn).rgnBBox;
-
- ODSShort top = shapeRect.top;
- ODSShort left = shapeRect.left;
- ODSShort bottom = shapeRect.bottom;
- ODSShort right = shapeRect.right;
-
- DebugStr("\pInspect Shape.");
- }
- //--------------------------------------------------------------------
- // SetMenuItemText
- //--------------------------------------------------------------------
- void SetMenuItemText( Environment* ev, ODID command, ODID cmdTextID )
- {
- Str63 text;
- ODIText* menuItem = kODNULL;
-
- ODSLong tRef;
- tRef = BeginUsingLibraryResources();
-
- TRY
-
- // Load the command text from the menu strings list resource
- GetIndString(text, kMenuStringResID, cmdTextID);
-
- // Create the itext string
- menuItem = CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text);
-
- // Change the menu item
- if ( menuItem )
- gGlobals->fMenuBar->SetItemString(ev, command, menuItem);
-
- // Dispose the menu text, since the menu bar makes a copy
- DisposeIText(menuItem);
-
- CATCH_ALL
- DebugStr("\pSetMenuItemText Failed.");
- ENDTRY;
-
- EndUsingLibraryResources(tRef);
-
- }
-
- //--------------------------------------------------------------------
- // ValueOnClipboard
- //--------------------------------------------------------------------
-
- ODBoolean ValueOnClipboard(Environment *ev, ODValueType type, ODSession* session)
- {
- ODBoolean result = kODFalse;
- ODClipboard* clipboard = session->GetClipboard(ev);
-
- TRY
- ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
- result = su->Exists(ev, kODPropContents, type, 0);
- CATCH_ALL
- ENDTRY
-
- return result;
- }
-
- //--------------------------------------------------------------------
- // CheckAndResolvePromisedShapes
- //
- // Iterate over the given list of shapes. If any of them are promised
- // then fulfill the promise on the clipboard.
- //--------------------------------------------------------------------
-
- void CheckAndResolvePromisedShapes(Environment *ev,
- COrderedList* shapeList,
- ODSession* session)
- {
- // Before removing / deleting shapes check to see if they
- // are promised to the clipboard.
- COrdListIterator iter(shapeList);
-
- // We only need to do the resolve for one promised shape.
- ODBoolean foundPromisedShape = kODFalse;
- for (CShape* shape = (CShape*)iter.First();
- iter.IsNotComplete()&&!foundPromisedShape;
- shape = (CShape*)iter.Next())
- {
- if (shape->IsPromisedToClipboard())
- ::ResolveClipboardPromises(ev, session);
- return;
- }
- }
-
- //--------------------------------------------------------------------
- // LoadTempMemPicture
- //--------------------------------------------------------------------
-
- PicHandle ODLoadPicture(ODSShort id)
- {
- TRY
- return (PicHandle)(::ODReadResource( 'PICT', id ));
- CATCH_ALL
- #ifdef ODDebug
- DebugStr("\pLoad of picture Failed.");
- #endif
- ENDTRY
-
- return kODNULL;
- }
-
-
- //--------------------------------------------------------------------
- // DeletePicture
- //--------------------------------------------------------------------
-
- void ODDeletePicture(PicHandle thePict)
- {
- ::ODDisposeHandle((ODHandle)thePict);
- }
-
-
-
- //--------------------------------------------------------------------
- // ResolveClipboardPromises
- //--------------------------------------------------------------------
-
- void ResolveClipboardPromises(Environment *ev, ODSession* session)
- {
- ODClipboard* clipboard = session->GetClipboard(ev);
-
- TRY
-
- if (gGlobals->fClipboardPromise)
- {
- if (clipboard->GetUpdateID(ev) == gGlobals->fClipboardPromise->GetUpdateID())
- {
- ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
- su->ResolveAllPromises(ev);
- }
- else
- {
- // Mark shapes as promised to the clipboard
- gGlobals->fClipboardPromise->ShapesPromisedToClipboard(ev, kODFalse);
-
- delete gGlobals->fClipboardPromise;
- gGlobals->fClipboardPromise = kODNULL;
- }
- }
-
- CATCH_ALL
- ENDTRY
- }
-
- //=========================================================================
- // StorageUnit I/O
- //=========================================================================
-
- //-------------------------------------------------------------------------
- // StorageUnitSetISOStrValue -- Write out string length and string to currently focused stream
- //-------------------------------------------------------------------------
-
- void StorageUnitSetISOStrValue( ODStorageUnit* su,
- Environment* ev,
- ODISOStr value)
- {
- ODULong size = strlen(value)+1;
- StorageUnitSetValue(su, ev, sizeof(ODULong), &size);
- StorageUnitSetValue(su, ev, size, (ODValue)value);
- }
-
- //-------------------------------------------------------------------------
- // StorageUnitGetISOStrValue -- Read in string length and string from currently focused stream
- // Allocate space for result.
- //-------------------------------------------------------------------------
-
- ODISOStr StorageUnitGetISOStrValue( ODStorageUnit* su,
- Environment* ev)
- {
- ODULong size;
- StorageUnitGetValue(su, ev, sizeof(ODULong), &size);
- ODISOStr value = (ODISOStr)::ODNewPtr(size);
- StorageUnitGetValue(su, ev, size, value);
-
- return value;
- }
-
-
- //--------------------------------------------------------------------
- // SetPartName
- //--------------------------------------------------------------------
-
- void SetPartName(Environment* ev, ODPart* part, ODIText* partName)
- {
- ODStorageUnit* storageUnit = part->GetStorageUnit(ev);
-
- if ( storageUnit->Exists(ev, kODPropName, kODMacIText, 0) )
- {
- // The fact that ODSetITextProp takes an ev parameter means it could fail
- TRY
- ODSetITextProp(ev, storageUnit, kODPropName, kODMacIText, partName);
- CATCH_ALL
- ENDTRY
- }
- }
-
- //--------------------------------------------------------------------
- // GetEditorScriptLanguage
- //--------------------------------------------------------------------
-
- void GetEditorScriptLanguage(Environment* ev, ODScriptCode* script,
- ODLangCode* language)
- {
- typedef struct versResource {
- // Not accurrate template, just used to get at the region code.
- // (see Inside Mac: Toolbox Essentials 7-70)
- long versionNumberStuff;
- unsigned short regionCode;
- Str255 versionNumberString;
- Str255 versionMessageString;
- } versResource, **versResourceHdl;
-
- OSErr error = noErr;
- long region;
-
- ODSLong tRef;
- tRef = BeginUsingLibraryResources();
- {
- Handle versHdl = GetResource('vers', 1);
-
- // Get the region code of the editor, otherwise use the
- // region code the of the primary system script.
-
- if ( versHdl )
- {
- region = (long)(*(versResourceHdl)versHdl)->regionCode;
- ReleaseResource(versHdl);
- }
- else
- {
- region = GetScriptManagerVariable(smRegionCode);
- }
-
- // Spanish & Japanese are not actually supported by the editor.
- // They are provided as examples of how to add recognition of
- // additional regions (see Script.h for region codes).
-
- switch ((short)region) {
- case verUS:
- *script = smRoman;
- *language = langEnglish;
- break;
- case verSpain:
- *script = smRoman;
- *language = langSpanish;
- break;
- case verJapan:
- *script = smJapanese;
- *language = langJapanese;
- break;
- default:
- *script = smRoman;
- *language = langEnglish;
- }
- }
- EndUsingLibraryResources(tRef);
- }
-
- //--------------------------------------------------------------------
- // FixedToIntRect
- //--------------------------------------------------------------------
-
- void FixedToIntRect(ODRect& fixedRect, Rect& intRect)
- {
- intRect.top = FixedToInt(fixedRect.top);
- intRect.left = FixedToInt(fixedRect.left);
- intRect.bottom = FixedToInt(fixedRect.bottom);
- intRect.right = FixedToInt(fixedRect.right);
- }
-
- //--------------------------------------------------------------------
- // IntToFixedRect
- //--------------------------------------------------------------------
-
- void IntToFixedRect(Rect& intRect, ODRect& fixedRect)
- {
- fixedRect.left = ff(intRect.left);
- fixedRect.top = ff(intRect.top);
- fixedRect.right = ff(intRect.right);
- fixedRect.bottom = ff(intRect.bottom);
- }
-
-
- //--------------------------------------------------------------------
- // LoadThumbnail
- //--------------------------------------------------------------------
-
- void LoadThumbnail(Environment* ev, Handle* thumbnail)
- {
- if ( *thumbnail ) return;
-
- ODSLong tRef;
- tRef = BeginUsingLibraryResources();
- {
- *thumbnail = (Handle) ::ODLoadPicture(kThumbnailPICT);
- }
- EndUsingLibraryResources(tRef);
- }
-
- //--------------------------------------------------------------------
- // TilePartWindow
- //--------------------------------------------------------------------
-
- Rect TilePartWindow(Environment* ev, Rect* facetBounds, Rect* partWindowBounds)
- {
- const short kWindowTilingConst = 20;
- const short kLeftToRight = 0;
- const short kRightToLeft = -1;
-
- short direction;
-
- // Get the direction for the primary script system running on this machine.
- // (Right-to-Left or Left-to-Right)
- direction = GetSysDirection();
-
- // The child window should be tiled from the topLeft corner of the
- // active facet whose frame is being opened.
- if ( direction == kLeftToRight )
- {
- // Position the window rect at the top/left corner of the facet.
- OffsetRect(partWindowBounds, facetBounds->left, facetBounds->top);
- // Now tile the window rect down and to the right.
- OffsetRect(partWindowBounds, kWindowTilingConst, kWindowTilingConst);
- }
- // The child window should be tiled from the topRight corner of the
- // active facet whose frame is being opened.
- else if ( direction == kRightToLeft )
- {
- // Position the window rect at the top/right corner of the facet.
- OffsetRect(partWindowBounds, (partWindowBounds->right - facetBounds->right),
- facetBounds->top);
- // Now tile the window rect down and to the left.
- OffsetRect(partWindowBounds, -kWindowTilingConst, kWindowTilingConst);
- }
-
- return *partWindowBounds;
- }
-
- //--------------------------------------------------------------------
- // CountFacets
- //--------------------------------------------------------------------
-
- ODUShort CountFramesFacets(Environment* ev, ODFrame* frame)
- {
- ODUShort facetCount = 0;
- ODFacet* facet;
-
- TempODFrameFacetIterator ffiter(ev, frame);
- facet = ffiter.First();
- while ( ffiter.IsNotComplete() )
- {
- facetCount++;
- facet = ffiter.Next();
- }
-
- return facetCount;
- }
-
- //=========================================================================
- // CCloneInfo
- //=========================================================================
- CCloneInfo::CCloneInfo(ODDraftKey key, ODDraft* fromDraft,
- ODFrame* scopeFrame, ODCloneKind kind )
- {
- fKey = key;
- fFromDraft = fromDraft;
- fScopeFrame = scopeFrame;
- fCloneKind = kind;
- }
-
-
- CCloneInfo::~CCloneInfo()
- {
- }
-
-
-
- //=========================================================================
- // CFrameInfo
- //=========================================================================
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CFrameInfo
- //-------------------------------------------------------------------------
-
- CFrameInfo::CFrameInfo()
- {
- fFrameActive = kODFalse;
- fFrameReactivate = kODFalse;
- fShouldDisposeWindow = kODFalse;
- fActiveFacet = kODNULL;
- fSourceFrame = kODNULL;
- fAttachedFrame = kODNULL;
- fPartWindow = kODNULL;
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::~CFrameInfo
- //-------------------------------------------------------------------------
-
- CFrameInfo::~CFrameInfo()
- {
- ODSafeReleaseObject(fAttachedFrame);
- ODSafeReleaseObject(fSourceFrame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::Externalize
- //-------------------------------------------------------------------------
-
- void CFrameInfo::Externalize(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- this->CleanseFrameInfoProperty(ev, storageUnit);
- this->ExternalizeFrameInfo(ev, storageUnit, 0, kODNULL);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CleanseFrameInfoProperty
- //-------------------------------------------------------------------------
-
- void CFrameInfo::CleanseFrameInfoProperty(Environment* ev, ODStorageUnit* storageUnit)
- {
- ODULong numValues;
- ODULong index;
-
- numValues = storageUnit->CountValues(ev);
-
- for (index = numValues; index >= 1; index--)
- {
- // Index, from 1 to n, through the values.
- storageUnit->Focus(ev, kODNULL, kODPosSame,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType value = storageUnit->GetType(ev);
-
- // If the value type is not one we support, remove it.
- if ( ODISOStrCompare(value, kDrawEditorInfo) != 0 )
- storageUnit->Remove(ev);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ExternalizeFrameInfo
- //-------------------------------------------------------------------------
-
- void CFrameInfo::ExternalizeFrameInfo(Environment* ev, ODStorageUnit* storageUnit,
- ODDraftKey key, ODFrame* scopeFrame)
- {
- // This method behaves much the same way as the SamplePart::ExternalizeStateInfo
- // method.
-
- if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) )
- {
- // Persistent object references are stored in a side table, rather than
- // in the property/value stream. Thus, deleting the contents of a value
- // will not "delete" the references previously written to that value. To
- // completely "delete" all references written to the value, we must
- // remove the value and add it back.
-
- storageUnit->Focus(ev, kODNULL, kODPosSame, kDrawEditorInfo, 0 , kODPosUndefined);
- storageUnit->Remove(ev);
- }
-
- if ( fSourceFrame )
- {
- ODStorageUnitRef weakRef;
- ODID frameID = fSourceFrame->GetID(ev);
- ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
- ODDraft* fromDraft = fSourceFrame->GetStorageUnit(ev)->GetDraft(ev);
-
- storageUnit->AddValue(ev, kDrawEditorInfo);
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
- TRY
- StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), (ODPtr)&weakRef);
- CATCH_ALL
- ENDTRY
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::CloneInto
- //-------------------------------------------------------------------------
-
- void CFrameInfo::CloneInto(Environment *ev, ODDraftKey key,
- ODStorageUnitView* storageUnitView, ODFrame* scopeFrame)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) == kODFalse )
- {
- this->ExternalizeFrameInfo(ev, storageUnit, key, scopeFrame);
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::InitFromStorage
- //------------------------------------------------------------------------------
-
- void CFrameInfo::InitFromStorage(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- // This method assumes that OpenDoc has passed us a storageUnitView
- // that is focused to a property, but no particular value.
-
- ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
-
- if ( storageUnit->Exists(ev, kODNULL, kDrawEditorInfo, 0) )
- {
- TRY
- storageUnit->Focus(ev, kODNULL, kODPosSame,
- kDrawEditorInfo, 0 , kODPosUndefined);
-
- ODULong size = storageUnit->GetSize(ev);
-
- // If the frame does not have a source frame, make sure the value
- // is empty.
- if ( size > 0 )
- {
- ODStorageUnitRef weakRef;
-
- StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
- (ODPtr)&weakRef);
-
- if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
- {
- ODID sourceID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
- ODFrame* frame = storageUnit->GetDraft(ev)->AcquireFrame(ev, sourceID);
-
- fSourceFrame = frame;
- }
- else
- {
- fSourceFrame = kODNULL;
- }
- }
-
- CATCH_ALL
- fSourceFrame = kODNULL;
- ENDTRY
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::SetSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::SetSourceFrame(Environment* ev, ODFrame* sourceFrame)
- {
- if ( sourceFrame != kODNULL )
- {
- ODAcquireObject(ev, sourceFrame);
- ODReleaseObject(ev, fSourceFrame);
- fSourceFrame = sourceFrame;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::ReleaseSourceFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::ReleaseSourceFrame(Environment* ev)
- {
- ODReleaseObject(ev, fSourceFrame);
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::AttachFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::AttachFrame(Environment* ev, ODFrame* frame)
- {
- if ( frame != kODNULL )
- {
- ODAcquireObject(ev, frame);
- ODReleaseObject(ev, fAttachedFrame);
- fAttachedFrame = frame;
- }
- }
-
- //-------------------------------------------------------------------------
- // CFrameInfo::DetachFrame
- //-------------------------------------------------------------------------
-
- void CFrameInfo::DetachFrame(Environment* ev)
- {
- ODReleaseObject(ev, fAttachedFrame);
- }
-
-
-
-